package com.zhu.wx.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhu.wx.entity.HandleMsg;
import com.zhu.wx.entity.RecMsg;
import com.zhu.wx.entity.ResMsg;
import com.zhu.wx.mapper.HandleMsgMapper;
import com.zhu.wx.mapper.RecMsgMapper;
import com.zhu.wx.mapper.ResMsgMapper;
import com.zhu.wx.strategy.WxRecStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 文本消息服务类
 * <xml>
 *   <ToUserName><![CDATA[toUser]]></ToUserName>
 *   <FromUserName><![CDATA[fromUser]]></FromUserName>
 *   <CreateTime>1348831860</CreateTime>
 *   <MsgType><![CDATA[text]]></MsgType>
 *   <Content><![CDATA[this is a test]]></Content>
 *   <MsgId>1234567890123456</MsgId>
 * </xml>
 *  参数	描述
 *  ToUserName	开发者微信号
 *  FromUserName	发送方帐号（一个OpenID）
 *  CreateTime	消息创建时间 （整型）
 *  MsgType	消息类型，文本为text
 *  Content	文本消息内容
 *  MsgId	消息id，64位整型
 */
@Service
public class WxRecTextService implements WxRecStrategy {
    @Autowired
    HandleMsgMapper handleMsgMapper;
    @Autowired
    ResMsgMapper resMsgMapper;
    @Override
    public ResMsg execute(RecMsg recMsg) {
        String content = recMsg.getContent();
        HandleMsg handleMsg = handleMsgMapper.selectOne(Wrappers.<HandleMsg>lambdaQuery().eq(HandleMsg::getKeyword, content));
        if(handleMsg == null){
            return null;
        }
        return resMsgMapper.selectById(handleMsg.getResMsgId());
    }
}
